/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ws
 * Date: 2023-01-07
 * Time: 20:17
 */
public class Solution {
}
//https://leetcode.cn/problems/design-circular-queue/submissions/393649228/
class MyCircularQueue {
    //空出一个位置作为分割
    private int[] arr;
    private int front;
    private int rear;//不存储数值

    public MyCircularQueue(int k) {
        arr = new int[k + 1];
    }

    public boolean enQueue(int value) {
        if (isFull()) {
            return false;
        }
        arr[rear] = value;
        rear = (rear + 1) % arr.length;//保证循环的下标始终合法
        return true;
    }

    public boolean deQueue() {
        if (isEmpty()) {
            return false;
        }
        front = (front + 1) % arr.length;//同样确保下标合法
        return true;
    }

    public int Front() {
        if (isEmpty()) {
            return -1;
        }
        return arr[front];
    }

    public int Rear() {
        if (isEmpty()) {
            return -1;
        }
        //需要考虑循环到起点时的情况（rear==0），此时rear不能简单地-1
        int index = rear == 0 ? arr.length - 1 : rear - 1;
        return arr[index];
    }

    public boolean isEmpty() {
        return rear == front;
    }

    public boolean isFull() {
        return (rear + 1) % arr.length == front;
    }
}

/**
 * Your MyCircularQueue object will be instantiated and called as such:
 * MyCircularQueue obj = new MyCircularQueue(k);
 * boolean param_1 = obj.enQueue(value);
 * boolean param_2 = obj.deQueue();
 * int param_3 = obj.Front();
 * int param_4 = obj.Rear();
 * boolean param_5 = obj.isEmpty();
 * boolean param_6 = obj.isFull();
 */